package com.googlecode.entity_dao.core.entity;

import java.io.Serializable;

import javax.persistence.MappedSuperclass;

/**
 * Base class for persistent entities managed within the JPA persistence context.
 * 
 * <p>
 * 
 * Note that this class does NOT provide any special {@link #hashCode()} and {@link #equals(Object)} implementation -
 * this is a task left to be done, depending on the chosen method implementation pattern.
 * 
 * <p>
 * 
 * This class implicitly supports the {@link Object#clone() clone} operation. Subclasses can implement {@link Cloneable}
 * interface if they wish to add explicit <tt>clone</tt> operation support.
 * 
 * @param <ID> Java type of the primary key column.
 * 
 * @see Persistable
 * 
 * @author vojtech.szocs
 * @author mauro.franceschini
 */
@MappedSuperclass
public abstract class PersistentEntity<ID extends Serializable> implements Persistable<ID> {

    private static final long serialVersionUID = -3831662382201152789L;

    protected static final String _ID = "ID";

    public abstract ID getId();

    protected abstract void setId(ID id);

    @Override
    protected Object clone() throws CloneNotSupportedException {
        @SuppressWarnings("unchecked")
        PersistentEntity<ID> clone = PersistentEntity.class.cast(super.clone());
        clone.setId(null);
        return clone;
    }
}
